﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel.Composition;

namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(IOrderItem))]
    public partial class OrderItem : Entity, IOrderItem
    {
        IOrder _order;
        IOrder IOrderItem.Order
        {
            get
            {
                if (this._order == null)
                {
                    this._order = this.DataContext.Orders.Where(i => i.Id == this.OrderId).FirstOrDefault();
                }
                return this._order;
            }
            set
            {
                this._order = value;
                this.OrderId = value.Id;
            }
        }

        List<IPromotionRule> _Promotions;
        public List<IPromotionRule> Promotions
        {
            get
            {
                if (this._Promotions == null)
                {
                    this._Promotions = new List<IPromotionRule>();
                }
                return this._Promotions;
            }
        }


        List<IOrderItemCustomField> _OrderItemCustomFields2;
        List<IOrderItemCustomField> IOrderItem.OrderItemCustomFields
        {
            get
            {
                if (this._OrderItemCustomFields2 == null)
                {
                    this._OrderItemCustomFields2 = this.DataContext.OrderItemCustomFields
                        .Where(i => i.OrderItemId == this.Id)
                        .Select(i => i as IOrderItemCustomField)
                        .ToList();
                }

                return this._OrderItemCustomFields2;
            }
            set
            {
                this._OrderItemCustomFields2 = value;
            }
        }

        List<IOrderItemVariation> _OrderItemVariations2;
        List<IOrderItemVariation> IOrderItem.OrderItemVariations
        {
            get
            {
                if (this._OrderItemVariations2 == null)
                {
                    this._OrderItemVariations2 = this.DataContext.OrderItemVariations
                        .Where(i => i.OrderItemId == this.Id)
                        .Select(i => i as IOrderItemVariation)
                        .ToList();
                }

                return this._OrderItemVariations2;
            }
            set
            {
                this._OrderItemVariations2 = value;
            }
        }
    }
}
